package se.djupfeldt.oscar.logbook.utils;

import java.util.Properties;

public class TypedProperties extends Properties {

    /**
     * 
     */
    private static final long serialVersionUID = -4583247263225286684L;

    public int getInt(String key, int defaultValue) {
	String s = getProperty(key);
	if (s == null || s.isEmpty())
	    return defaultValue;
	else {
	    try {
		return Integer.parseInt(s);
	    } catch (NumberFormatException e) {
		return defaultValue;
	    }
	}
    }
    
    public double getDouble(String key, double defaultValue) {
	String s = getProperty(key);
	if (s == null || s.isEmpty())
	    return defaultValue;
	else {
	    try {
		return Double.parseDouble(s);
	    } catch (NumberFormatException e) {
		return defaultValue;
	    }
	}
    }
    
    public boolean getBoolean(String key, boolean defaultValue) {
	String s = getProperty(key);
	if (s == null || s.isEmpty())
	    return defaultValue;
	else {
	    try {
		return Boolean.parseBoolean(s);
	    } catch (NumberFormatException e) {
		return defaultValue;
	    }
	}
    }
}
